<script setup>
import { ref, nextTick, watch, onMounted } from 'vue'
import {
    Document,
    Menu as IconMenu,
    Location,
    Setting,
    Ship,
    Odometer,
    Histogram,
    Coin

} from '@element-plus/icons-vue'
import * as echarts from 'echarts';
import Info31 from './Info3-1.vue'
import Info32 from './Info3-2.vue'
// import { el } from 'element-plus/es/locale';

let myChart;
let chartDom;
var option;
const show_chart = ref(true)
const Selectvalue1 = ref('Changjiangkou(Estuary)')
const Selectvalue2 = ref('全部')

const cities = ref([
    {
        value: 'Changjiangkou(Estuary)',
        label: 'Changjiangkou(Estuary)'
    },
    {
        value: 'Columbia River(Estuary)',
        label: 'Columbia River(Estuary)'
    },
    {
        value: 'Mississippi River(Estuary)',
        label: 'Mississippi River(Estuary)'
    },
    {
        value: 'Panama(Atlantic-Pacific)',
        label: 'Panama(Atlantic-Pacific)',
    },
    {
        value: 'Panama(Pacific-Atlantic)',
        label: 'Panama(Pacific-Atlantic)',
    },
    {
        value: 'Suez(Mediterranean-Red Sea)',
        label: 'Suez(Mediterranean-Red Sea)',
    },
])

const Shoptype=ref([
// 全部
// 其他类型船舶
// 散货船
// 杂货船
// 气槽船
// 石油化学品船
// 集装箱船
{
    value:'全部',
    label:'全部'
},
{
    value:'其他类型船舶',
    label:'其他类型船舶'
},
{
    value:'散货船',
    label:'散货船'
},
{
    value:'杂货船',
    label:'杂货船'
},
{
    value:'气槽船',
    label:'气槽船'
},
{
    value:'石油化学品船',
    label:'石油化学品船'
},
{
    value:'集装箱船',
    label:'集装箱船'
},
])
function loadchart() {
    nextTick(() => {
        for (let i = 0; i < ChartList.value.length; i++) {
            let base = +new Date(2022, 11, 3);
            let oneDay = 24 * 3600 * 1000;
            let date = [];
            let data = [Math.random() * 300];
            for (let i = 1; i < 100; i++) {
                var now = new Date((base += oneDay));
                date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
                data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
            }

            //随机生成
            option = {
                tooltip: {
                    trigger: 'axis',
                    position: function (pt) {
                        return [pt[0], '10%'];
                    }
                },
                title: {
                    left: 'center',
                    text: ChartList.value[i].name
                },
                // toolbox: {
                //     feature: {
                //         dataZoom: {
                //             yAxisIndex: 'none'
                //         },
                //         restore: {},
                //         saveAsImage: {}
                //     }
                // },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: date
                },
                yAxis: {
                    type: 'value',
                    boundaryGap: [0, '100%']
                },
                // dataZoom: [
                //     {
                //         type: 'inside',
                //         start: 0,
                //         end: 10
                //     },
                //     {
                //         start: 0,
                //         end: 10
                //     }
                // ],
                series: [
                    {
                        name: 'Fake Data',
                        type: 'line',
                        symbol: 'none',
                        sampling: 'lttb',
                        itemStyle: {
                            color: 'rgb(255, 70, 131)'
                        },
                        areaStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                {
                                    offset: 0,
                                    color: 'rgb(255, 158, 68)'
                                },
                                {
                                    offset: 1,
                                    color: 'rgb(255, 70, 131)'
                                }
                            ])
                        },
                        data: data
                    }
                ]
            };
            chartDom = document.getElementById(ChartList.value[i].id);
            myChart = echarts.init(chartDom);
            option && myChart.setOption(option);
        }
        // if(myChart) myChart.dispose()
        // chartDom = document.getElementById('zhujiangkou');
        // myChart = echarts.init(chartDom);
        // option && myChart.setOption(option);
    })
}
const ChartList = ref([
    {
        name: '珠江口',
        id: 'zhujiangkou'
    },
    {
        name: '长江口',
        id: 'cahngjiangkou'
    },
    {
        name: 'Mississippi',
        id: 'Mississippi'
    },
    {
        name: 'Columbia',
        id: 'Columbia'
    },
    {
        name: 'Suez(Mediterranean-Red Sea)',
        id: 'Suez(Mediterranean-Red Sea)'
    },
    {
        name: 'Suez(Red Sea-Mediterranean)',
        id: 'Suez(Red Sea-Mediterranean)'
    },
    {
        name: 'Panama(Atlantic-Pacific)',
        id: 'Panama(Atlantic-Pacific)'
    },
    {
        name: 'Panama(Pacific-Atlantic)',
        id: 'Panama(Pacific-Atlantic)'
    }
])
const isCollapse = ref(false)
const handleOpen = (key, keyPath) => {
    console.log(key, keyPath)
}
const handleClose = (key, keyPath) => {
    console.log(key, keyPath)
}
const activeIndex = ref('1')
const activeIndex2 = ref('1')
const handleSelect = (key, keyPath) => {
    console.log(key, keyPath)
    if (key == 1) {
        show_chart.value = true
        loadchart()
    } else {
        show_chart.value = false
    }
}
const Allclose = () => {
    show_chart.value = true
}
onMounted(() => {
    loadchart()
})
</script>

<template>
    <div class="Menu-left">
        <!-- <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
            <el-radio-button :label="false">expand</el-radio-button>
            <el-radio-button :label="true">collapse</el-radio-button>
        </el-radio-group> -->
        <el-menu default-active="2" class="el-menu-vertical-demo" :collapse="isCollapse" @open="handleOpen"
            @close="handleClose">
            <el-menu-item index="1">
                <el-icon>
                    <Ship />
                </el-icon>
                <template #title>船舶压港</template>
            </el-menu-item>
            <el-menu-item index="2">
                <el-icon>
                    <Odometer />
                </el-icon>
                <template #title>平均航速</template>
            </el-menu-item>
            <el-menu-item index="3">
                <el-icon>
                    <Histogram />
                </el-icon>
                <template #title>航运指数</template>
            </el-menu-item>
            <el-menu-item index="4">
                <el-icon>
                    <Coin />
                </el-icon>
                <template #title>商品价格</template>
            </el-menu-item>
        </el-menu>
    </div>

    <div class="Right">
        <div class="Menu-top">
            <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
                <el-menu-item index="1">运河/河口</el-menu-item>
                <el-menu-item index="2">巴拿马运河新旧闸</el-menu-item>
                <el-menu-item index="3">散货船</el-menu-item>
                <el-menu-item index="4">集装箱船</el-menu-item>
                <el-menu-item index="5">关注泊位</el-menu-item>
            </el-menu>
        </div>
        <div class="Info" v-if="show_chart">
            <div class="Info-1">
                <el-row>
                    <el-col :span="6" v-for="item in ChartList">
                        <div class="chart" :id="item.id"></div>
                    </el-col>
                </el-row>
            </div>
            <div class="Info-2">
                <el-row style="margin: 1vh;">
                    <el-col :span="1" class="selecttitle">
                        位置：
                    </el-col>
                    <el-col :span="6">
                        <el-select v-model="Selectvalue1" placeholder="Select" size="large" style="width: 90%;">
                            <el-option v-for="item in cities" :key="item.value" :label="item.label" :value="item.value">
                                <span style="float: left">{{ item.value }}</span>
                                <!-- <span style="float: right;  color: var(--el-text-color-secondary);  font-size: 13px;">
                                    {{ item.value }}
                                </span> -->
                            </el-option>
                        </el-select>

                    </el-col>
                    <el-col :span="1" class="selecttitle">
                        船型：
                    </el-col>
                    <el-col :span="6">
                        <el-select v-model="Selectvalue2" placeholder="Select" size="large" style="width: 90%;">
                            <el-option v-for="item in Shoptype" :key="item.value" :label="item.label" :value="item.value">
                                <span style="float: left">{{ item.label }}</span>
                                <!-- <span style="float: right;  color: var(--el-text-color-secondary);  font-size: 13px;">
                                    {{ item.value }}
                                </span> -->
                            </el-option>
                        </el-select>

                    </el-col>
                    <el-col :span="6" class="selectbutton">
                        <el-button type="primary">权限</el-button>
                        <el-button type="success">查询</el-button>
                    </el-col>
                </el-row>
            </div>
            <div class="Info-3">
                <el-row>
                    <el-col :span="12">
                        <div class="Info3title">锚泊数量和平均锚泊时长 </div>
                        <Info31 />
                    </el-col>
                    <el-col :span="12">
                        <div class="Info3title">锚泊数量和平均锚泊时长 </div>
                        <Info32 />
                    </el-col>
                </el-row>
            </div>
            <div>

            </div>
        </div>
    </div>
</template>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    //   min-height: 400px;
    height: 100%;
}

.el-menu-demo {
    width: 100%;
}

.Menu-left {
    width: 220px;
    height: 100%;
    border-right: 1px solid var(--el-color-border-Base);
}

.Right {
    width: calc(100% - 220px);
    height: 100%;

    .Menu-top {
        height: 60px;
        border-bottom: 1px solid var(--el-color-border-Base);
    }

    .Info {
        height: calc(100% - 60px);
        // height: 200px;
        // height: 800px;
        // background-color: aqua;
        overflow-y: scroll;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
    }
}

.Info-1 {
    // background-color: var(--el-color-primary);
    width: 100%;
    // height: 90vh;
}

.Info-2 {
    width: 99%;
    height: 70px;
    border-radius: 4px;
    margin: 0.5vh 0.5vw;
    background-color: rgba(2, 2, 2, 0.073);
    display: flex;
    justify-content: center;
    align-items: center;

    .selecttitle {
        font-size: 15px;
        font-weight: 600;
        color: var(--el-text-color-secondary);
        text-align: center;
        display: flex;
        align-items: center;
    }

    .selectbutton {
        display: flex;
        justify-content: flex-end;
    }
}

.Info-3 {
    width: 100%;
    // height: 70vh;
    // background-color: rgba(2, 2, 2, 0.829);
    display: flex;
    justify-content: center;
    align-items: center;
}

.Info3title {
    font-size: 20px;
    font-weight: 600;
    color: var(--el-text-color-secondary);
    text-align: center;
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    margin: 1vh 2vw;
}

.chart {
    height: 250px;
    // width: 25%;
    margin: 5px;
    // background-color: aqua;
    border: 4px solid var(--el-color-border-Base);
    border-radius: 10px;
}

.el-sub-menu__title {
    font-size: 5px !important;
}

.el-row {
    margin-bottom: 20px;
    width: 100%;
}

.el-row:last-child {
    margin-bottom: 0;
}

.el-col {
    border-radius: 4px;
    width: 25%;
}

.grid-content {
    // width: 25%;
    border-radius: 4px;
    min-height: 36px;
    background-color: bisque;
}</style>